﻿Imports MySql.Data.MySqlClient
Imports conn
Public Class Main_Login
    Public dbversion
    Private Sub OK_Click() Handles OK.Click
        conn.connection.conn()
        Dim command = New MySqlCommand
        command.CommandText = "SELECT * FROM `members` WHERE `username` = '" & UsernameTextBox.Text.ToLower & "' AND `password` = '" & functions.MD5_Hash(PasswordTextBox.Text) & "' " 'Query to exectue.
        command.Connection = connection.MyADOConnection
        Dim read = command.ExecuteReader
        read.Read() 'Opens the reader.
        If read.HasRows Then
            details.username = read.GetString(1) 'Gets the data from the database
            details.name = read.GetString(5) & " " & read.GetString(6)
            details.money = read.GetString(4)
            read.Close() 'Closes the reader
            conn.connection.MyADOConnection.Close() 'Closes the database connection
            Main.Show()
            Me.Close()
        Else
            MsgBox("Sorry there has been a problem logging you in.", MsgBoxStyle.Critical)
            MsgBox("Check your details and try again.", MsgBoxStyle.Critical)
            read.Close() 'Closes the reader
            connection.MyADOConnection.Close() 'Closes the database connection
        End If
    End Sub
    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        End
    End Sub
    Private Sub Main_Login_Load() Handles MyBase.Load
        functions.Connection_Check()
        functions.Check_Version(My.Application.Info.Version.Build & "." & My.Application.Info.Version.Revision)
        Me.BackColor = details.backcolor
        If My.User.Name = "BENS\Ben Burt" Then
            btnburtylogin.Visible = True
        ElseIf My.User.Name = "Steve-PC\Steve" Then
            btnstevelogin.Visible = True
        End If
    End Sub
    Private Sub btnburtylogin_Click() Handles btnburtylogin.Click
        UsernameTextBox.Text = "burtybob"
        PasswordTextBox.Text = "benburtabc123"
        OK_Click()
    End Sub
    Private Sub btnstevelogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstevelogin.Click
        UsernameTextBox.Text = "SSaywell"
        PasswordTextBox.Text = "3050"
        OK_Click()
    End Sub
    Private Sub btnreged_Click() Handles btnreged.Click
        panregornot.Dispose()
    End Sub
    Private Sub Load_Register_Form() Handles btnnewacc.Click
        panregornot.Dispose()
        Register.Show()
        Me.Close()
    End Sub
    Private Sub Close_Form(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PicExit.Click
        Me.Close()
    End Sub
End Class
